<?php

namespace App\Admin\Extensions\Table;

use App\Admin\Repositories\Post;
use App\Admin\Repositories\ShopGood;
use App\Models\Partition;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class PostsTable extends LazyRenderable
{
    public function grid(): Grid
    {
        // 获取外部传递的参数
        $user_id = $this->user_id;
        return Grid::make(new Post(), function (Grid $grid) use ($user_id) {
            $grid->disableCreateButton();
            $grid->disableBatchActions();
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->model()->where("user_id",$user_id)->with(['topic']);
            $grid->column('id')->sortable();
            $grid->column('type')->using(['图片','视频'])->label(['info','success']);
            $grid->column('images','帖子图片')->image(null,40,40);
//            $grid->column('video','帖子视频')->link();
            $grid->column('content','帖子内容')->limit(15);
            $grid->column('topic.title','话题');
            $grid->column('status')->radio(['上架','下架'],true)->label(['info','default']);
            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->expand(false);
                $filter->equal('id')->width(3);
                $filter->like('user.name','发帖人姓名')->width(3);
                $filter->equal('type')->select(['图片','视频'])->width(3);
                $filter->equal('status')->select(['上架','下架'])->width(3);
                $filter->between('created_at')->date()->width(3);
            });
            $grid->paginate(8);
        });
    }


}
